package org.third.common.utils;

import java.util.HashMap;
import java.util.Map;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;

/**
 * Created by Huailong Tang(Jason) on 2017/8/25.
 */
public class HttpBuilder {

  private HttpHeaders httpHeaders = new HttpHeaders();

  private Map<String,String> uriVariables = new HashMap<>();

  private HttpEntity httpEntity;


  public HttpBuilder setHeader(String key,String value) {
    httpHeaders.set(key,value);
    return this;
  }

  public HttpBuilder setVariable(String key,String value) {
    uriVariables.put(key,value);
    return this;
  }

  public HttpEntity buildEntity() {
    httpEntity = new HttpEntity(httpHeaders);
    return httpEntity;
  }

  public <T> HttpEntity buildEntityWithBody(T t) {
    if(t == null) {
      return new HttpEntity(httpHeaders);
    }
    return new HttpEntity(t, httpHeaders);

  }

  public Map<String,String> buildVariables() {
    return uriVariables;
  }

}
